const cloud = require('wx-server-sdk')
const db = cloud.database();

exports.main = async (event,context)=>{
  console.log(event.data);
	let query =  db.collection('edge_like').where({
		user:event.data.user,
    liker:event.data.liker,
    edge_id:event.data.edge_id
	})
  let result = await query.count();
  console.log(result)
	let infos;
	if(result.total===0){
		infos = await db.collection('edge_like').add({
			data:event.data
		})
	}else{
		delete event.data.create_at_utc;
		infos = await query.update({
			data:event.data
		})
	}
	return {'msg':'ok','data':infos}
}